/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.task.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.core.dao.SysUserDao;
import com.tech15.core.model.SysUser;
import com.tech15.task.model.*;
import com.tech15.task.dao.*;
import com.tech15.task.service.*;
import com.tech15.task.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */

@Service
@Transactional
public class TaskAuthManager extends BaseManager<TaskAuth,Long>{

	private TaskAuthDao taskAuthDao;
	private SysUserDao sysUserDao;
	
	public void setSysUserDao(SysUserDao sysUserDao) {
		this.sysUserDao = sysUserDao;
	}
	public void setTaskAuthDao(TaskAuthDao dao) {
		this.taskAuthDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.taskAuthDao;
	}
	
	public TaskAuth getById(Long id){
		TaskAuth auth = taskAuthDao.getById(id);
		if(auth != null){
			if(auth.getAuthid() != null){
				SysUser user = sysUserDao.getById(auth.getAuthid());
				if(user != null){
					auth.setAuthname(user.getRealname());
				}
			}
		}
		return auth;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(TaskAuthQuery query) {
		return taskAuthDao.findPage(query);
	}
	
	@Transactional(readOnly=true)
	public Page findByPageRequest(PageRequest pr) {
		return taskAuthDao.findByPageRequest(pr);
	}
	public void updateTaskAuth(TaskAuth taskAuth) {
		TaskAuth auth = taskAuthDao.getById(taskAuth.getUserid());
		if(auth != null){
			auth.setAuthid(taskAuth.getAuthid());
			taskAuthDao.update(auth);
		}else{
			taskAuthDao.save(taskAuth);
		}
		//taskAuthDao.saveOrUpdate(taskAuth);
	}
	
}
